package patrol.mobile.com.mobilepatrol.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.yanghuke.zuoyefenbu.ZuoyeFenbuDetailActivity;
import patrol.mobile.com.mobilepatrol.bean.DingweiBean;

/**
 * Created by z on 2018/9/8.
 * Des:作业分布适配器
 */

public class ZuoYeFenbuAdapter extends RecyclerView.Adapter<ZuoYeFenbuAdapter.ViewHolder> {
    public DingweiBean getDingweiBean() {
        return dingweiBean;
    }

    private DingweiBean dingweiBean;
    private OnLocationListener onLocationListener;

    public void setOnLocationListener(OnLocationListener onLocationListener) {
        this.onLocationListener = onLocationListener;
    }

    public interface OnLocationListener {
        void onclick(int postion);
    }

    public void setDingweiBean(DingweiBean dingweiBean) {
        this.dingweiBean = dingweiBean;
        notifyDataSetChanged();
    }

    @Override
    public ZuoYeFenbuAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_zuoyefenbu_layout,
                parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ZuoYeFenbuAdapter.ViewHolder holder, final int position) {
        holder.itemNum.setText(position + 1 + "");
        holder.itmeTitle.setText(dingweiBean.getList().get(position).getRoutelinename() + "线");
//        holder.itemType.setText(dingweiBean.getList().get(position).getRoutelinename() + "  " + dingweiBean.getList().get(position).getPot());
        holder.itemType.setText(dingweiBean.getList().get(position).getOrgName().concat(" ")+dingweiBean.getList().get(position).getWorksTeam());
        holder.shengheType.setText(dingweiBean.getList().get(position).getAuditName());
        holder.itemTypeContent.setText(dingweiBean.getList().get(position).getWorksInfo());
        holder.itemTimeTextView.setText(dingweiBean.getList().get(position).getUpdateDate());
        holder.itemZhuanhaoTextView.setText("桩号：" + dingweiBean.getList().get(position).getPot());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.getContext().startActivity(new Intent(v.getContext(), ZuoyeFenbuDetailActivity.class)
                        .putExtra("data", dingweiBean.getList().get(position)));
            }
        });
        holder.iv_loc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onLocationListener.onclick(holder.getPosition());
            }
        });
    }

    @Override
    public int getItemCount() {
        return dingweiBean == null ? 0 : dingweiBean.getList().size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_num)
        TextView itemNum;
        @BindView(R.id.itmeTitle)
        TextView itmeTitle;
        @BindView(R.id.itemType)
        TextView itemType;
        @BindView(R.id.shengheType)
        TextView shengheType;
        @BindView(R.id.itemTypeContent)
        TextView itemTypeContent;
        @BindView(R.id.itemTimeTextView)
        TextView itemTimeTextView;
        @BindView(R.id.itemZhuanhaoTextView)
        TextView itemZhuanhaoTextView;
        @BindView(R.id.iv_loc)
        ImageView iv_loc;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
